﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class CompanyWeek
    {
        public static void insert(CompanyWeekEntity companyWeek)
        {
            DbHelper.ExecuteNonQuery("p_CompanyWeek_insert",
              companyWeek.CompanyId,
              companyWeek.Weekday,
              companyWeek.Products,
              companyWeek.CustomerId
               );
        }

        public static void update(CompanyWeekEntity companyWeek)
        {
            DbHelper.ExecuteNonQuery("p_CompanyWeek_update",
              companyWeek.CsId,             
              companyWeek.Products
               );
        }

        public static CompanyWeekEntity getById(int csId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_CompanyWeek_getById", csId);
            CompanyWeekEntity companyWeek = new CompanyWeekEntity();
            if (dr != null)
            {
                companyWeek.CsId = csId;
                companyWeek.CompanyId = Convert.ToInt32(dr["companyId"]);
                companyWeek.Weekday = Convert.ToInt32(dr["weekday"]);
                companyWeek.Products = dr["products"].ToString();
                companyWeek.CustomerId = Convert.ToInt32(dr["customerId"]);
                if (dr["updateDt"] == DBNull.Value)
                    companyWeek.UpdateDt = Convert.ToDateTime(dr["updateDt"]);
            }
            return companyWeek;
        }

        public static CompanyWeekEntity getByWeek(int weekday,int companyId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_CompanyWeek_getByWeek", weekday, companyId);
            CompanyWeekEntity companyWeek = new CompanyWeekEntity();
            if (dr != null)
            {
                companyWeek.CsId = Convert.ToInt32(dr["csId"]);
                companyWeek.CompanyId = companyId;
                companyWeek.Weekday = weekday;
                companyWeek.Products = dr["products"].ToString();
                companyWeek.CustomerId = Convert.ToInt32(dr["customerId"]);
                if (dr["updateDt"]==DBNull.Value)
                    companyWeek.UpdateDt = Convert.ToDateTime(dr["updateDt"]);
            }
            return companyWeek;
        }

        public static void delete(int csId)
        {
            DbHelper.ExecuteNonQuery("p_CompanyWeek_delete",
                csId);
        }


        public static DataTable getByProducts(string products)
        {
           return  DbHelper.ExecuteDataTable("p_CompanyWeek_getByProducts",
                products);
        }

        public static DataTable getProductsWithPriceByWeek(int weekday, int companyId)
        {
            return DbHelper.ExecuteDataTable("p_CompanyWeek_getProductsWithPriceByWeek",
                 weekday, companyId);
        }
    }

}
